<%@ page import="com.apexedu.identity.security.CasLoginUtil" %>
<%@ page import="com.apexedu.portal.constant.Constants" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%
    request.setAttribute("basePath", request.getContextPath());
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
    <title><%=Constants.ProjectInfo.PROJECT_NAME%>
    </title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <link href="${basePath}/resources/css/mh.shmy.css" rel="stylesheet">
    <script type="text/javascript" src="${basePath}/clientui/js/jquery-1.4.js"></script>
    <script src="${basePath}/resources/js/mh.shmy.index.js" type="text/javascript"></script>
    <script>
        function doreset() {
            $(":password").val("");
        }
        function doSubmit() {
            var oldpwd = $("#userPwdOld").val().replace(/(^\s*)|(\s*$)/g, "");
            var userPwd = $("#userPwd").val().replace(/(^\s*)|(\s*$)/g, "");
            var dlmmnew2 = $("#dlmmnew2").val().replace(/(^\s*)|(\s*$)/g, "");
            if (userPwd == "") {
                alert("新密码不能为空！");
                return false;
            }
            if (userPwd != dlmmnew2) {
                alert("两次输入的密码不一致");
                return false;
            }
            if (oldpwd == "") {
                alert("原密码不能为空");
                return false;
            }
            $.post('${basePath}/s/uc/us/cs', {pwd: encodeURIComponent(oldpwd)}, function (data) {
                if (data == 'true') {
                    $.post('${basePath}/s/uc/us/ms', {pwd: encodeURIComponent(userPwd)}, function (data) {
                        if (data == 'true') {
                            alert("修改密码成功！");
                            $.get("${basePath}/identity/ajaxlogin.action?act=logout", {q: (new Date()).getTime()}, function (data) {
                                data = eval("(" + data + ")");
                                if (data.msg == 'success') {
                                    <%
                                if( CasLoginUtil.isSsoEnabled() ){
                                %>
                                    <%--window.location.href = '<%=CasLoginUtil.getCasServerLogoutUrl()%>';--%>
                                    window.location.href = '/';
                                    <%
                                    }else{
                                    %>
                                    window.location.href = '<%=request.getContextPath() %>?t=' + Math.round(new Date / 1000);
                                    <%
                                    }
                                    %>
                                } else {
                                    alert(data.msg);
                                }
                            });
                        } else {
                            alert("修改密码失败！");
                        }
                    });
                } else {
                    alert("原密码输入有误,请重新输入");
                }
            });
        }

        function doNext() {
            var userPwd = $("#userPwd").val().replace(/(^\s*)|(\s*$)/g, "");
            var dlmmnew2 = $("#dlmmnew2").val().replace(/(^\s*)|(\s*$)/g, "");
            if (userPwd == "") {
                alert("新密码不能为空！");
                return false;
            }
            if (userPwd != dlmmnew2) {
                alert("两次输入的密码不一致");
                return false;
            }
            $.post('${basePath}/s/uc/us/ms', {pwd: encodeURIComponent(userPwd)}, function (data) {
                if (data == 'true') {
                    alert("修改密码成功！");
                    $.get("${basePath}/identity/ajaxlogin.action?act=logout", {q: (new Date()).getTime()}, function (data) {
                        data = eval("(" + data + ")");
                        if (data.msg == 'success') {
                            <%
                        if( CasLoginUtil.isSsoEnabled() ){
                        %>
                            <%--window.location.href = '<%=CasLoginUtil.getCasServerLogoutUrl()%>';--%>
                            window.location.href = '/';
                            <%
                            }else{
                            %>
                            window.location.href = '<%=request.getContextPath() %>?t=' + Math.round(new Date / 1000);
                            <%
                            }
                            %>
                        } else {
                            alert(data.msg);
                        }
                    });
                } else {
                    alert("修改密码失败！");
                }
            });
        }
    </script>
</head>
<body>
<div id="main">
    <jsp:include page="left.jsp"/>
    <div id="right">
        <jsp:include page="head.jsp"/>
        <div id="contentSub">
            <div>
                <fieldset style="border: 1px solid #ccc;">
                    <c:choose>
                        <c:when test="${type=='find'}">
                            <legend style="font-size: 18px;text-align: left;">3、修改密码</legend>
                        </c:when>
                        <c:otherwise>
                            <legend style="font-size: 18px;text-align: left;">密码修改</legend>
                        </c:otherwise>
                    </c:choose>
                    <table class="tableStyle" style="background-color: transparent;">
                        <c:choose>
                            <c:when test="${type=='find'}">
                            </c:when>
                            <c:otherwise>
                                <tr>
                                    <td width="30%" height="35" align="right">原密码：</td>
                                    <td width="70%" align="left">
                                        <input type="password" id="userPwdOld" tabindex="2" maxlength="50" size="15"
                                               name="tsysUser.username">
                                        <font color="#FF0000">*</font> <font color="#666666">输入您正在使用的密码，用于确认您的身份！</font>
                                    </td>
                                </tr>
                            </c:otherwise>
                        </c:choose>
                        <tr>
                            <td width="30%" height="35" align="right">新密码：</td>
                            <td width="70%" align="left">
                                <input type="password" id="userPwd" tabindex="2" maxlength="50" size="15"
                                       name="tsysUser.userpwd" class="textinput">
                                <font color="#FF0000">*</font> <font color="#666666">输入新密码！</font>
                            </td>
                        </tr>
                        <tr>
                            <td width="30%" height="35" align="right">确认新密码：</td>
                            <td width="70%" align="left">
                                <input type="password" maxlength="50" size="15" id="dlmmnew2" name="dlmmnew2"
                                       class="textinput">
                                <font color="#FF0000">*</font> <font color="#666666">请再输入一次上面写的新密码！</font>
                            </td>
                        </tr>

                        <tr>
                            <td width="80%" height="50" align="left" colspan="4" style="text-align: center;">
                                <c:choose>
                                    <c:when test="${type=='find'}">
                                        <input type="button" onclick="window.location.href = '${basePath}/s/mh/fp/qe'"
                                               value="上一步" class="button">
                                        <input type="button" onclick="doNext()" value="提交" class="button">
                                    </c:when>
                                    <c:otherwise>
                                        <input type="button" onclick="doSubmit()" value="提交" class="button">
                                        <input type="button" onclick="doreset()" value="清除" class="button">
                                    </c:otherwise>
                                </c:choose>
                            </td>
                            <td width="20%" style="text-align: center; "></td>
                        </tr>
                    </table>
                </fieldset>
            </div>
        </div>
        <jsp:include page="foot.jsp"/>
    </div>
</div>
</body>
</html>
